package joc.internal;

import java.io.IOException;
import java.io.InputStream;

import joc.internal.util.SortedProperties;

import org.apache.log4j.Logger;

public class ConfigCache {
	private static SortedProperties configCache;
	private static final Logger logger = Logger.getLogger(ConfigCache.class);

	public static final String PATH = "/joc.properties";

	public static final String PREFIX_EXTERNAL = "external_";
	public static final String PREFIX_ACTION = "action_";
	public static final String PREFIX_CONTRACT = "contract_";
	public static final String PREFIX_ENABLE = "enable_";
	public static final String PREFIX_GENERAL = "_";

	public static final String ON = "On";

	public static synchronized SortedProperties getConfig() {
		if (configCache == null) {
			configCache = new SortedProperties();
			InputStream propertiesStream = Evaluator.class.getResourceAsStream(PATH);
			if (propertiesStream != null) {
				try {
					configCache.load(propertiesStream);
					logger.info("Loaded '" + PATH + "'.");
				} catch (IOException e) {
					logger.warn("Couldn't load '" + PATH + "'.", e);
				}
			} else {
				logger.info("Couldn't find '" + PATH + "'.");
			}
		}
		return configCache;
	}
}
